npm 您所在的位置:网站首页 install type u npm

npm

2024-06-29 18:10| 来源: 网络整理| 查看: 265

npm-install安装包

选择 CLI 版本:

目录 概要

¥Synopsis

npm install [ ...] aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall 描述

¥Description

此命令安装一个包和它所依赖的任何包。如果包有一个包锁,或者一个 npm 收缩封装文件,或者一个 Yarn 锁文件,依赖的安装将由它驱动,遵循以下优先顺序:

¥This command installs a package and any packages that it depends on. If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that, respecting the following order of precedence:

npm-shrinkwrap.json

package-lock.json

yarn.lock

见 package-lock.json 和 npm shrinkwrap。

¥See package-lock.json and npm shrinkwrap.

一个 package 是:

¥A package is:

a) 包含由 package.json 文件描述的程序的文件夹

¥a) a folder containing a program described by a package.json file

b) 一个 gzipped tarball,包含 (a)

¥b) a gzipped tarball containing (a)

c) 解析为 (b) 的 url

¥c) a url that resolves to (b)

d) 在注册表上发布的 @(参见 registry),带有 (c)

¥d) a @ that is published on the registry (see registry) with (c)

e) 指向 (d) 的 @(见 npm dist-tag)

¥e) a @ (see npm dist-tag) that points to (d)

f) 具有满足 (e) 的 "latest" 标签的

¥f) a that has a "latest" tag satisfying (e)

g) 解决为 (a) 的

¥g) a that resolves to (a)

即使你从不发布你的包,如果你只是想写一个 node 程序(a),你仍然可以获得使用 npm 的很多好处,也许你还想在打包后能够轻松地安装它成一个 tarball (b)。

¥Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).

npm install(在包目录中,无参数):

¥npm install (in a package directory, no arguments):

将依赖安装到本地 node_modules 文件夹。

¥Install the dependencies to the local node_modules folder.

在全局模式下(即,将 -g 或 --global 附加到命令中),它将当前包上下文(即当前工作目录)安装为全局包。

¥In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.

默认情况下,npm install 将安装 package.json 中列为依赖的所有模块。

¥By default, npm install will install all modules listed as dependencies in package.json.

使用 --production 标志(或者当 NODE_ENV 环境变量设置为 production 时),npm 将不会安装 devDependencies 中列出的模块。当 NODE_ENV 环境变量设置为 production 时,要安装 dependencies 和 devDependencies 中列出的所有模块,你可以使用 --production=false。

¥With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies. To install all modules listed in both dependencies and devDependencies when NODE_ENV environment variable is set to production, you can use --production=false.

注意:在向项目添加依赖时,--production 标志没有特殊含义。

¥NOTE: The --production flag has no particular meaning when adding a dependency to a project.

npm install :

如果 位于项目的根目录中,它的依赖将被安装,并且可能会像其他类型的依赖一样被提升到顶层 node_modules。如果 位于项目根目录之外,npm 不会在目录 中安装包依赖,但会创建到 的符号链接。

¥If sits inside the root of your project, its dependencies will be installed and may be hoisted to the top-level node_modules as they would for other types of dependencies. If sits outside the root of your project, npm will not install the package dependencies in the directory , but it will create a symlink to .

注意:如果你想从注册表安装目录的内容(如包)而不是创建链接,则需要使用 --install-links 选项。

¥NOTE: If you want to install the content of a directory like a package from the registry instead of creating a link, you would need to use the --install-links option.

示例:

¥Example:

npm install ../../other-package --install-linksnpm install ./sub-package

npm install :

安装位于文件系统上的包。注意:如果你只想将一个 dev 目录链接到你的 npm 根目录,你可以使用 npm link 更容易地做到这一点。

¥Install a package that is sitting on the filesystem. Note: if you just want to link a dev directory into your npm root, you can do this more easily by using npm link.

压缩包要求:

¥Tarball requirements:

文件名必须使用 .tar、.tar.gz 或 .tgz 作为扩展名。

¥The filename must use .tar, .tar.gz, or .tgz as the extension.

包内容应位于 tarball 内的子文件夹中(通常称为 package/)。npm 在安装包时剥离一个目录层(运行 tar x --strip-components=1 的等效项)。

¥The package contents should reside in a subfolder inside the tarball (usually it is called package/). npm strips one directory layer when installing the package (an equivalent of tar x --strip-components=1 is run).

包必须包含具有 name 和 version 属性的 package.json 文件。

¥The package must contain a package.json file with name and version properties.

示例:

¥Example:

npm install ./package.tgz

npm install :

获取 tarball url,然后安装它。为了区分此选项和其他选项,参数必须以 "http://" 或 "https://" 开头

¥Fetch the tarball url, and then install it. In order to distinguish between this and other options, the argument must start with "http://" or "https://"

示例:

¥Example:

npm install https://github.com/indexzero/forever/tarball/v0.5.6

npm install [/]:

进行 @ 安装,其中 是 "tag" 配置。(参见 config。配置的默认值为 latest。)

¥Do a @ install, where is the "tag" config. (See config. The config's default value is latest.)

在大多数情况下,这将在 npm 注册表上安装标记为 latest 的模块版本。

¥In most cases, this will install the version of the modules tagged as latest on the npm registry.

示例:

¥Example:

npm install sax

默认情况下,npm install 将任何指定的包保存到 dependencies 中。此外,你可以使用一些额外的标志来控制它们的保存位置和方式:

¥npm install saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:

-P, --save-prod:包将出现在你的 dependencies 中。这是默认值,除非存在 -D 或 -O。

¥-P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.

-D, --save-dev:包将出现在你的 devDependencies 中。

¥-D, --save-dev: Package will appear in your devDependencies.

-O, --save-optional:包将出现在你的 optionalDependencies 中。

¥-O, --save-optional: Package will appear in your optionalDependencies.

--no-save:防止保存到 dependencies。

¥--no-save: Prevents saving to dependencies.

当使用上述任何选项将依赖保存到 package.json 时,还有两个额外的可选标志:

¥When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:

-E, --save-exact:保存的依赖将使用精确的版本进行配置,而不是使用 npm 的默认 semver 范围运算符。

¥-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.

-B, --save-bundle:保存的依赖也将添加到你的 bundleDependencies 列表中。

¥-B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.

此外,如果你有 npm-shrinkwrap.json 或 package-lock.json,那么它也会被更新。

¥Further, if you have an npm-shrinkwrap.json or package-lock.json then it will be updated as well.

是可选的。该包将从与指定范围关联的注册表中下载。如果没有注册表与给定范围关联,则假定为默认注册表。见 scope。

¥ is optional. The package will be downloaded from the registry associated with the specified scope. If no registry is associated with the given scope the default registry is assumed. See scope.

注意:如果你不在范围名称中包含 @ 符号,npm 会将其解释为 GitHub 存储库,请参见下文。范围名称后还必须跟一个斜杠。

¥Note: if you do not include the @-symbol on your scope name, npm will interpret this as a GitHub repository instead, see below. Scopes names must also be followed by a slash.

示例:

¥Examples:

npm install saxnpm install githubname/reponamenpm install @myorg/privatepackagenpm install node-tap --save-devnpm install dtrace-provider --save-optionalnpm install readable-stream --save-exactnpm install ansi-regex --save-bundle

注意:如果当前工作目录中有一个名为 的文件或文件夹,那么它将尝试安装它,如果它无效,则仅尝试按名称获取包。

¥Note: If there is a file or folder named in the current working directory, then it will try to install that, and only try to fetch the package by name if it is not valid.

npm install @npm::

在自定义别名下安装包。允许并排同名包的多个版本,更方便地导入具有其他长包的名称,并使用 git forks 替换或复刻的 npm 包作为替换。别名仅适用于你的项目,不会重命名传递依赖中的包。别名应遵循 validate-npm-package-name 中规定的命名约定。

¥Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side, more convenient import names for packages with otherwise long ones, and using git forks replacements or forked npm packages as replacements. Aliasing works only on your project and does not rename packages in transitive dependencies. Aliases should follow the naming conventions stated in validate-npm-package-name.

示例:

¥Examples:

npm install my-react@npm:reactnpm install jquery2@npm:jquery@2npm install jquery3@npm:jquery@3npm install npa@npm:npm-package-arg

npm install [/]@:

安装指定标签引用的包的版本。如果该包的注册表数据中不存在该标记,则此操作将失败。

¥Install the version of the package that is referenced by the specified tag. If the tag does not exist in the registry data for that package, then this will fail.

示例:

¥Example:

npm install sax@latestnpm install @myorg/mypackage@latest

npm install [/]@:

安装指定版本的包。如果版本尚未发布到注册表,这将失败。

¥Install the specified version of the package. This will fail if the version has not been published to the registry.

示例:

¥Example:

npm install [email protected] install @myorg/[email protected]

npm install [/]@:

安装与指定版本范围匹配的包版本。这将遵循 package.json 中描述的解决依赖的相同规则。

¥Install a version of the package matching the specified version range. This will follow the same rules for resolving dependencies described in package.json.

请注意,大多数版本范围必须放在引号中,以便你的 shell 将其视为单个参数。

¥Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.

示例:

¥Example:

npm install sax@">=0.1.0 =0.1.0


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有